#include "string.h"

class Solution {
public:
    bool isLetterOrNum(char ch)
    {
        if ((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')||(ch>='A'&&ch<='Z')) return true;
        return false;
    }

    bool isPalindrome(string s) {
        for (auto& ch : s) {
            if (ch >= 'A' && ch <= 'Z') ch += 32;
        }
        int begin = 0, end = s.size() - 1;
        while (begin < end) {
            while (begin < end && !isLetterOrNum(s[begin])) ++begin;
            while (begin < end && !isLetterOrNum(s[end])) --end;
            if (s[begin] != s[end]) return false;
            else {
                ++begin, --end;
            }
        }
        return true;
    }
};